
const app = getApp();

var shareTicket, that, sessionKey, encryptedData;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    className: '',
    userinfo: wx.getStorageSync('userinfo'),
    formatList: '',
    name: '',
    count: '',
    changeName: '',
    changeCount: '',
    id:''
  },
  nameIn: function (e) {
  //   if(e.detail.value.length>=0&&e.detail.value.length<21){
  //     this.data.infoArray.name = e.detail.value
  //   }
  //   else{
  //     wx.showToast({
  //       title: '名称输入错误',
  //       icon:'loading'
  //     })
  //   }
  // },
  // numIn: function (e) {
  //   if(Number(e.detail.value)>0&&Number(e.detail.value)<250){
  //     this.data.infoArray.count = e.detail.value
  //   }
  //   else{
  //     wx.showToast({
  //       title: '人数输入错误',
  //       icon:'loading'
  //     })
  //   }
    this.data.name = e.detail.value
  },
  numIn: function (e) {
    if(!(/^[0-9]{0,3}$/.test(e.detail.value))){
      wx.showToast({
        title: '请输入数字',
        icon: 'none',    //如果要纯文本，不要icon，将值设为'none'
        duration: 1000    //持续时间为 2秒
      }) 
      this.setData({
        count: ''
      })
    }else {
      this.setData({
        count: e.detail.value
      })
    }
  },
  // 提取输入框中的数字部分
  // validateNumber(val) {
  //   return val.replace(/\D/g, '')
  // },
  // 显示删除提示弹框
  showDeleteClass(e) {
    this.setData({
      id: e.target.dataset.id,
      modalName: e.currentTarget.dataset.target
    })
  },
  hideDeleteDialog(e) {
    this.setData({
      modalName: null
    })
  },

  // 删除模板
  deleteFormat: async function () {
    console.log('id'+this.data.id);
    await wx.User.delFormat(this.data.id)
    this.setData({
      modalName: null
    })
    this.onShow()

    
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userinfo: wx.getStorageSync('userinfo')
    })
    console.log(this.data.userinfo);
    wx.User.getFormatList({
      data:{
        uid:wx.getStorageSync('userinfo').uid},
    })
    this.setData({
      formatList:wx.getStorageSync('formatList')
    })
    console.log(this.data.formatList);
    shareTicket = app.shareTicket;
    /*
     * withShareTicket:true
     * 被打开的时候，可以获取一些信息，例如：群标识   
     * onLaunch / onShow  获取到shareTicket
     */
  },
  //创建签到
  creatSign: function(e){
    // var id = e.currentTarget.dataset.id
    // console.log("kkkk");
    // console.log(id);
    // wx.User.creatSignFormat(id)
    var id = e.currentTarget.dataset.id
    console.log("kkkk");
    console.log(id);
    wx.navigateTo({
      url: './format_middle?id='+id,
    })
  },

  addFormat: function () {
    wx.navigateTo({
      url: './format_launch',
    })
  },
  getupdateFormat: function (e) {
    var id = e.currentTarget.dataset.id
    console.log("kkkk");
    console.log(id);
    wx.navigateTo({
      url: './qurup_format?id='+id,
    })
  },
  formatSign: function (e) {
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: './format_sign?id='+id,
    })
  },
  showModal(e) {
    this.setData({
      modalName: e.currentTarget.dataset.target
    })
  },
  hideModal(e) {
    this.setData({
      modalName: null
    })
  },
 
  
 
  onLaunch: function (e) {
    if (e.scene == 1044) {
    }
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function (res) {
    await wx.User.getFormatList({
      data:{
        uid:wx.getStorageSync('userinfo').uid},
    })
    this.setData({
      formatList:wx.getStorageSync('formatList')
    })
    console.log(this.data.formatList);
  },
  /**
   * getOpenGid 获取群标识openGId
   */
  getOpenGid: function () {
    that = this;
    wx.getShareInfo({
      shareTicket: shareTicket,
      success: (res) => {
      },
      fail: (error) => {
      }
    })
  },

  // ListTouch触摸开始
  ListTouchStart(e) {
    this.setData({
      ListTouchStart: e.touches[0].pageX
    })
  },

  // ListTouch计算方向
  ListTouchMove(e) {
    this.setData({
      ListTouchDirection: e.touches[0].pageX - this.data.ListTouchStart > 0 ? 'right' : 'left'
    })
  },

  // ListTouch计算滚动
  ListTouchEnd(e) {
    if (this.data.ListTouchDirection == 'left') {
      this.setData({
        modalName: e.currentTarget.dataset.target
      })
    } else {
      this.setData({
        modalName: null
      })
    }
    this.setData({
      ListTouchDirection: null
    })
  },
})